<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>计算器</title>
</head>
<body>
	num1：<input type="text" id="num1" ><br><br>
	num2：<input type="text" id="num2" ><br><br>
	<button onclick="jisuan('+')" >+</button>
	<button onclick="jisuan('-')" >-</button>
	<button onclick="jisuan('*')" >x</button>
	<button onclick="jisuan('/')" >/</button><br>
	res：<input type="text" id="res" >
</body>
	<script>
	res = document.getElementById("res");
		function jisuan(m){
			num1 = parseInt(document.getElementById("num1").value);
			num2 = parseInt(document.getElementById("num2").value);
			// alert(num1);
			if(isNaN(num1)){
				alert("num1值必须为数字");
			}else if(isNaN(num2)){
				alert("num2值必须为数字");
			}else{
				switch(m){
					case "+":
						res.value=num1+"+"+num2+"="+(num1+num2);
						break;
					case "-":
						res.value=num1+"-"+num2+"="+(num1-num2);
						break;
					case "*":
						res.value=num1+"x"+num2+"="+(num1*num2);
						break;
					case "/":
						if(num2==0){
							alert("除数不能为0");
						}else{
							res.value=num1+"/"+num2+"="+(num1/num2);
						}
						break;
				}
			}
		}
	</script>
</html>